package com.jec.module.sysconfig.service.convertor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jec.module.sysconfig.dao.PhoneStationRepository;
import com.jec.module.sysconfig.entity.PhoneStation;
import com.jec.module.sysmonitor.dao.NetUnitRepository;
import com.jec.utils.Response;

/**
 * Created by jeremyliu on 08/10/2016.
 */
@Service
public class PhoneStationConvertor implements Convertor<PhoneStation>{

    @Autowired
    private NetUnitRepository netUnitRepository;

    @Autowired
    private PhoneStationRepository phoneStationRepository;

    @Override
    public Response process(PhoneStation phonestation) {
        Response response = Response.Builder().status(Response.STATUS_PARAM_ERROR);

        if(netUnitRepository.findOne(phonestation.getNetunit()) == null)
            return response.message("网元不存在");
        if(phoneStationRepository.existsByNetunitAndCodeAndIdNot(
        		phonestation.getNetunit(), 
        		phonestation.getCode(), 
        		phonestation.getId()))
            return response.message("该网元业务为"+phonestation.getCode()+"已配置");

        return response.status(Response.STATUS_SUCCESS);
    }

    @Override
    public Response checkBeforeRemove(int id) {
        return null;
    }
}
